#include "skiplist.h"
#include <iostream>
#include <thread>
#include <future>
#include <chrono>

void test1(SkipList<int, std::string> &skipList)
{
    for (int i = 1; i <= 20000; i++)
    {
        skipList.insert(i, std::to_string(i));
        // std::this_thread::sleep_for(std::chrono::duration<int,std::ratio<1,1000>>(1));
    }
}

void test2(SkipList<int, std::string> &skipList)
{
    for (int i = 20001; i <= 40000; i++)
    {
        skipList.insert(i, std::to_string(i));
        // std::this_thread::sleep_for(std::chrono::duration<int,std::ratio<1,1000>>(1));
    }
}

void test3(SkipList<int, std::string> &skipList)
{
    for (int i = 40001; i <= 60000; i++)
    {
        skipList.insert(i, std::to_string(i));
        // std::this_thread::sleep_for(std::chrono::duration<int,std::ratio<1,1000>>(1));
    }
}


int main()
{
    SkipList<int, std::string> skipList;
    skipList.loadFromFile("kvfile");
    std::thread t1(test1, std::ref(skipList));
    std::thread t2(test2, std::ref(skipList));
    std::thread t3(test3, std::ref(skipList));
    // std::future<void> fu = std::async(std::launch::deferred | std::launch::async, test, std::ref(skipList));
    t1.join();
    t2.join();
    t3.join();
    skipList.saveToFile("kvfile");
    skipList.print();
}